package lib.quasar.db.table;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Transient;

import java.io.Serializable;

import lib.quasar.context.BaseConstant;
import lib.quasar.recycler.model.MultModel;
import lib.quasar.widget.photo.PhotoModel;

@Entity
public class Chat implements MultModel, PhotoModel, Serializable {

    @Transient
    private static final long serialVersionUID = -4758750836621872195L;
    @Transient
    public final static String MESSAGE = "message"; // 文字消息
    @Transient
    public final static String PICTURE = "picture"; // 图片消息
    @Transient
    public final static String INSPECTION = "inspection"; // 化验单消息
    @Transient
    public final static String DIAGNOSE = "diagnose"; // 诊断消息
    @Transient
    public final static String ADVISE = "advise"; // 诊断消息

    @Transient
    public final static String PRESCRIPTION = "prescription"; // 调药消息

    /**********************************************************************************************/

    @Id(autoincrement = true) // 主键自增
    protected Long id_;

    private Long sendid;
    private String send_name = "";
    private String send_icon = "http://img3.duitang.com/uploads/item/201508/07/20150807082213_AcdWu.jpeg";

    private Long receiveid;
    private String receive_name = "";

    private String message_type = "";
    private String message = "";
    private String json_message_content = "";

    private String send_datetime = "";
    private String read_datetime = "";

    private Integer send_type; // 医生给患者0， 患者给医生1， 医生给医生2， 患者给患者3
    private Integer send_status = 2; //  1:发送开始, 2:发送成功, 3:发送失败
    private Integer status; // 消息状态(0:未读, 1:已读, 默认未读)

    private Long send_key = System.nanoTime();
    private Long send_timestamp = System.currentTimeMillis();

    @Generated(hash = 519536279)
    public Chat() {
    }

    @Generated(hash = 121747279)
    public Chat(Long id_, Long sendid, String send_name, String send_icon, Long receiveid, String receive_name, String message_type, String message, String json_message_content, String send_datetime, String read_datetime, Integer send_type, Integer send_status, Integer status, Long send_key, Long send_timestamp) {
        this.id_ = id_;
        this.sendid = sendid;
        this.send_name = send_name;
        this.send_icon = send_icon;
        this.receiveid = receiveid;
        this.receive_name = receive_name;
        this.message_type = message_type;
        this.message = message;
        this.json_message_content = json_message_content;
        this.send_datetime = send_datetime;
        this.read_datetime = read_datetime;
        this.send_type = send_type;
        this.send_status = send_status;
        this.status = status;
        this.send_key = send_key;
        this.send_timestamp = send_timestamp;
    }

    /**********************************************************************************************/

    public String getUrls() {

        if (json_message_content.isEmpty()) {
            return "";
        } else {
            return BaseConstant.API_URL + json_message_content;
        }
    }

    @Override
    public String getUrl() {
        return getUrls();
    }

    @Override
    public String getUrlLittle() {
        return getUrls();
    }

    @Override
    public int getMultType() {

        // 自己
        if (send_type.equals(1)) {

            if (MESSAGE.equals(message_type)) {

                //  Log.e("Chat", "自己 - 文字");
                return MultModel.TYPE_0;
            } else if (PICTURE.equals(message_type)) {

                //  Log.e("Chat", "自己 - 图片");
                return MultModel.TYPE_1;
            } else {

                //  Log.e("Chat", "自己 - 化验单, 诊断");
                return MultModel.TYPE_2;
            }
        }
        // 别人
        else {
            if (MESSAGE.equals(message_type)) {

                //   Log.e("Chat", "别人 - 文字");
                return MultModel.TYPE_3;
            } else if (PICTURE.equals(message_type)) {

                //   Log.e("Chat", "别人 - 图片");
                return MultModel.TYPE_4;
            } else {

                //   Log.e("Chat", "别人 - 化验单, 诊断");
                return MultModel.TYPE_5;
            }
        }
    }

    /**********************************************************************************************/

    public Long getSend_key() {
        return send_key;
    }

    public void setSend_key(Long send_key) {
        this.send_key = send_key;
    }

    public Long getId_() {
        return id_;
    }

    public void setId_(Long id_) {
        this.id_ = id_;
    }

    public Long getSendid() {
        return sendid;
    }

    public void setSendid(Long sendid) {
        this.sendid = sendid;
    }

    public String getSend_name() {
        return send_name;
    }

    public void setSend_name(String send_name) {
        this.send_name = send_name;
    }

    public Long getReceiveid() {
        return receiveid;
    }

    public void setReceiveid(Long receiveid) {
        this.receiveid = receiveid;
    }

    public String getReceive_name() {
        return receive_name;
    }

    public void setReceive_name(String receive_name) {
        this.receive_name = receive_name;
    }

    public String getMessage_type() {
        return message_type;
    }

    public void setMessage_type(String message_type) {
        this.message_type = message_type;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getJson_message_content() {
        return json_message_content;
    }

    public void setJson_message_content(String json_message_content) {
        this.json_message_content = json_message_content;
    }

    public String getSend_icon() {
        return send_icon;
    }

    public void setSend_icon(String send_icon) {
        this.send_icon = send_icon;
    }

    public String getSend_datetime() {
        return send_datetime;
    }

    public void setSend_datetime(String send_datetime) {
        this.send_datetime = send_datetime;
    }

    public String getRead_datetime() {
        return read_datetime;
    }

    public void setRead_datetime(String read_datetime) {
        this.read_datetime = read_datetime;
    }

    public Integer getSend_type() {
        return send_type;
    }

    public void setSend_type(Integer send_type) {
        this.send_type = send_type;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public boolean isSendSucc() {
        return send_status == 2;
    }

    public boolean isSendFail() {
        return send_status == 3;
    }

    public void setSendInit() {
        this.send_status = 1;
    }

    public void setSendSucc() {
        this.send_status = 2;
    }

    public void setSendFail() {
        this.send_status = 3;
    }

    public Integer getSend_status() {
        return this.send_status;
    }

    public void setSend_status(Integer send_status) {
        this.send_status = send_status;
    }

    public Long getSend_timestamp() {
        return send_timestamp;
    }

    public void setSend_timestamp(Long send_timestamp) {
        this.send_timestamp = send_timestamp;
    }

    /*****************************************************************************/

    public boolean isOwn(Long patientid) {
        if (null == patientid) return false;
        return sendid.equals(patientid);
    }

    public boolean isPicture() {
        return PICTURE.equals(message_type);
    }

    @Override
    public String toString() {
        return "Chat{" +
                "id_=" + id_ +
                ", sendid=" + sendid +
                ", send_name='" + send_name + '\'' +
                ", receiveid=" + receiveid +
                ", receive_name='" + receive_name + '\'' +
                ", message_type='" + message_type + '\'' +
                ", message='" + message + '\'' +
                ", json_message_content='" + json_message_content + '\'' +
                ", send_datetime='" + send_datetime + '\'' +
                ", read_datetime='" + read_datetime + '\'' +
                ", send_timestamp=" + send_timestamp +
                ", send_type=" + send_type +
                ", send_status=" + send_status +
                ", status=" + status +
                '}';
    }
}
